<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('设备列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <select title="打印机列表：" style="display: none" id="select-printlist"></select>
            <div id="preview-list" style="display: none"></div>
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>库房名称：</label>
                            <input id="treeId" name="storeroomId" type="hidden" />
                            <input type="text" onclick="selectAstStoreroomTree()" id="treeName" readonly="true">
                        </li>
                        <li>
                            <label>站点名称：</label>
                            <input id="siteId" name="siteId" type="hidden" />
                            <input type="text" onclick="selectAstSiteTree()" id="siteName" readonly="true" >
                        </li>
                        <li>
                            <label>设备名称：</label>
                            <input type="text" name="deviceName"/>
                        </li>
                        <li>
                            <label>设备类型：</label>
                            <select name="deviceType" th:with="type=${@dict.getType('ast_device_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>设备厂家：</label>
                            <input type="text" name="deviceFactory"/>
                        </li>
                        <li class="select-time">
                            <label>采购时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            <label>设备状态：</label>
                            <select name="status" th:with="type=${@dict.getType('ast_device_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="chongzhi()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="asset:astDevice:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="asset:astDevice:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="asset:astDevice:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: dayin-js" />
<script th:inline="javascript">
    var caozuoListFlag = [[${@permission.hasPermi('asset:deviceRecord:list')}]];
    var editFlag = [[${@permission.hasPermi('asset:astDevice:edit')}]];
    var removeFlag = [[${@permission.hasPermi('asset:astDevice:remove')}]];
    var statusDatas = [[${@dict.getType('ast_device_status')}]];
    var caozuoStatusDatas = [[${@dict.getType('ast_device_caozuo')}]];

    var prefix = ctx + "asset/astDevice";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "设备",
            columns: [{
                checkbox: true
            },
                {
                    field: 'deviceId',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'storeroomName',
                    title: '库房名称'
                },
                {
                    field: 'siteName',
                    title: '站点名称'
                },
                {
                    field: 'deviceName',
                    title: '设备名称'
                },
                {
                    field: 'deviceFactory',
                    title: '设备厂家'
                },
                {
                    field: 'devicePrice',
                    title: '单价'
                },
                {
                    field: 'deviceGuige',
                    title: '型号',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 8, "open");
                    }
                },
                {
                    field: 'deviceProcureTime',
                    title: '采购时间'
                },
                {
                    field: 'status',
                    title: '设备状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'deviceQrcodeImg',
                    title: '二维码',
                    formatter: function (value, row, index) {
                        return $.table.imageView(ctx + value);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建日期'
                },
                {
                    field: 'createBy',
                    title: '创建人'
                },
                {
                    field: 'caozuoStatus',
                    title: '最后操作状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(caozuoStatusDatas, value);
                    }
                },
                {
                    field: 'caozuoRen',
                    title: '最后操作人'
                },
                {
                    field: 'caozuoTime',
                    title: '最后操作时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    width:150,
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs ' + caozuoListFlag + '" style="margin: 5px" href="javascript:void(0)" onclick="caozuoList(\'' + row.deviceId + '\')"><i class="fa fa-list-ul"></i>操作记录</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.deviceId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="dayinQrcode(\''+row.deviceName+'\',\''+row.deviceGuige+'\',\''+row.deviceFactory+'\',\''+row.deviceQrcode+'\')"></i>打印二维码</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.deviceId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function chongzhi() {
        $("#treeId").val("")
        $("#siteId").val("")
        $.form.reset()
    }

    /*库房管理-新增-选择父库房管理树*/
    function selectAstStoreroomTree() {
        var options = {
            title: '库房选择',
            width: "380",
            url: ctx + "asset/astStoreroom/selectAstStoreroomTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }
    function doSubmit(index, layero){
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    /*站点管理-新增-选择父站点管理树*/
    function selectAstSiteTree() {
        var options = {
            title: '站点管理选择',
            width: "380",
            url: ctx + "asset/astSite/selectAstSiteTree/0",
            callBack: doSubmit2
        };
        $.modal.openOptions(options);
    }

    function doSubmit2(index, layero){
        var body = $.modal.getChildFrame(index);
        $("#siteId").val(body.find('#treeId').val());
        $("#siteName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    function dayinQrcode(deviceName,xinghao,gongsi,deviceQrcode) {
        drawTableTest(deviceName,xinghao,gongsi,deviceQrcode)
    }

    function caozuoList(deviceId) {
        var url = ctx + "asset/deviceRecord/"+deviceId;
        $.modal.openTab("设备操作记录", url);
    }

</script>
</body>
</html>